import Vue from 'vue'
import Vuex from 'vuex'
import apply from './modules/apply'
import createPersistedState from 'vuex-persistedstate'
Vue.use(Vuex)
const key = 'zzr_user'
export default new Vuex.Store({
  state: {
    userInfo: {},
    hasLogin: localStorage.getItem(key)?true:false,
    forceLogin: false,
    language:localStorage.getItem('langs')||'zh',
    LOGIN_TIPS_ALERT:localStorage.getItem('LOGIN_TIPS_ALERT')!=null?false:true
  },
  mutations: {
    login(state,value){
      state.hasLogin = true;
      state.userInfo = value
    },
    $_setStronge(state,value){
      localStorage.setItem(key,JSON.stringify(value))
    },
    $_removeStronge(state,key){
      localStorage.removeItem(key)
    },
    logOut(state,value){
      state.userInfo = {};
      localStorage.removeItem(key);
      state.hasLogin = false;
    },
    changeLanguage(state,lang){
			state.language = lang
		}
  },
  getters:{
    getStronge:function(state,key){
      if(!state.token){
        state.token =JSON.parse(localStorage.getItem(key))
      }
      return state.token
    }
  },
  actions: {
  },
  modules: {
    apply
  },
  plugins:[createPersistedState({
    key:'applyform',
    storage:window.sessionStorage,
    reducer(val){
      return{
        apply:val.userInfo
      }
    }
  })]
})
